package com.syezon.wifikey.wifi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.Utils;
import com.bumptech.glide.Glide;
import com.hodanet.appadvplatclient.ReportAgent;
import com.hodanet.appadvplatclient.ad.AdInfo;
import com.syezon.wifikey.R;
import com.syezon.wifikey.ad.AdPositionEnum;
import com.syezon.wifikey.ad.AdUtils;
import com.syezon.wifikey.channel.ChannelConfig;
import com.syezon.wifikey.view.verticalbannerview.BaseBannerAdapter;
import com.syezon.wifikey.view.verticalbannerview.VerticalBannerView;

import java.util.List;

/**
 * Created by Administrator on 2018/9/29.
 */

public class VerticalBannerAdapter extends BaseBannerAdapter<AdInfo> {

    private static final String TAG = VerticalBannerAdapter.class.getSimpleName();

    private Context mContext;

    public void setOnBannerClickListener(OnBannerClickListener onBannerClickListener) {
        this.onBannerClickListener = onBannerClickListener;
    }

    private OnBannerClickListener onBannerClickListener;
    public VerticalBannerAdapter(Context context, List<AdInfo> datas) {
        super(datas);
        this.mContext = context;
    }


    @Override
    public View getView(VerticalBannerView parentView) {
        return LayoutInflater.from(parentView.getContext()).inflate(R.layout.item_banner, parentView, false);
    }

    @Override
    public void setItem(View view, final AdInfo adInfo) {
        ImageView icon = (ImageView) view.findViewById(R.id.iv_icon);
        TextView tvTitle = (TextView) view.findViewById(R.id.tv_title);
        tvTitle.setText(adInfo.getName());
        if (!adInfo.isReportExtShow()) {
            ReportAgent.reportAdvExtShow(adInfo, ChannelConfig.getChannel(), AppUtils.getAppVersionCode());
            adInfo.setReportExtShow(true);
        }
        Glide.with(mContext).load(adInfo.getIcon()).into(icon);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onBannerClickListener != null) {
                    onBannerClickListener.onBannerClick(adInfo);
                }else {
                    AdUtils.adClicked(Utils.getApp(),adInfo,AdPositionEnum.BANNER_ME_TOP);
                }
            }
        });
    }
    public interface OnBannerClickListener {
        void onBannerClick(AdInfo adInfo);
    }
}
